#ifndef __THREAD_POOL__
#define __THREAD_POOL__

#include <my_header.h>
#include "stringStack.h"
#include "tidArr.h"
#include "taskQueue.h"
#include "myLog.h"
#include "directoryOperation.h"
#include "tlv.h"
#include "netCloud_mySql.h"
#include "fileTable.h"
struct threadPool_s;



typedef struct threadContext_s{
    //线程id，默认数组下标，作为以后系统线程ID拓展使用
    int threadID;
    pathStack_t *pstack;
    MYSQL * pthreadMysql;
    fileMetaData_t *pthreadFileMeta;
    //TLV_t *tlv;
    //这样设计是方便以后直接传入threadContext
    //前向技术
    struct threadPool_s *pthreadPool;
    
}threadContext_t;

typedef struct threadPool_s{
    tidArr_t tidArr;
    taskQueue_t taskQueue;
    pthread_mutex_t mutex;
    pthread_mutex_t sqlmutex;       
    pthread_cond_t cond;
    threadContext_t *pthreadContext;  
    int exitFlag;        
}threadPool_t;

int quit_user(int id, MYSQL *db);
int epollDel(int epfd,int fd);
int epollAdd(int epfd,int fd);
 int makeWorker(threadPool_t *pthreadPool);
int tcpInit(char * ip,char *port);
int create_encrypt(unsigned char*salt,char*password,unsigned char*digest);//加密文
int create_salt(unsigned  char*salt);
int send_all(int sockfd,const void *buf,size_t len);
  int sendTlv(int sockfd,TLV_t *tlv);
  int recv_all(int sockfd,void *buf,size_t len);
 int recvTlv(int sockfd,TLV_t* tlv);
int tackle_register(int socket, MYSQL *db,TLV_t*TLV_RECV);//处理注册，失败返回-1.成功返回id>
int get_user_id(MYSQL *db, const char *username);
int tackle_signin(int socket, MYSQL *db,TLV_t*TLV_RECV);//处理登录，失败返回-1，成功返回用户id
int quit_user(int id,MYSQL*db);//推出时使用，将表中的”已登录“标记清零
int delete_user(int id,MYSQL*db);
int threadPoolInit(threadPool_t *pthreadPool, int workNum);
int chooseOptin(TLV_t *tlv,int netfd,pathStack_t *pstack,MYSQL *pthreadMysql,fileMetaData_t * pthreadFileMeta);
#endif

